package br.com.localfloripa.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import br.com.localfloripa.converters.BaseEntity;

@Entity
@Table(name="estado")
public class Estado implements Serializable,BaseEntity {
	
	private static final long serialVersionUID = -1682401253232224593L;
	
	@SequenceGenerator(name="Estado_Seq",sequenceName="estado_seq")
	@Id @GeneratedValue(generator="Estado_Seq")
	private Long id;
	@Column(name="nome",nullable=false)
	private String nome;
	@Column(name="sigla",nullable=false)
	private String sigla;
	@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
	@Fetch(value=FetchMode.SUBSELECT)
	private List<Municipio> municipios;
	
	public Estado() {
		
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getSigla() {
		return sigla;
	}
	public void setSigla(String sigla) {
		this.sigla = sigla;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<Municipio> getMunicipios() {
		return municipios;
	}
	public void setMunicipios(List<Municipio> municipios) {
		this.municipios = municipios;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Estado other = (Estado) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}	
}
